package com.jd.threed.生产者消费者原理;



public class VolatileCanStop implements Runnable{

    private volatile boolean canlceld = false;


    @Override
    public void run() {

        int num = 0;

        try {
            while (!canlceld && num <10000){
                if (num % 10 ==0){
                    System.out.println(num + "是10 的倍数");
                }
                num++;
            }
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        VolatileCanStop volatileCanStop = new VolatileCanStop();

        Thread thread = new Thread(volatileCanStop);
        thread.start();
        thread.run();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        volatileCanStop.canlceld = true;

    }
}
